package com.mrs.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import cn.hutool.core.util.ArrayUtil;
import com.mrs.common.Result;
import com.mrs.entity.User;
import com.mrs.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * description: EchartsController
 * date: 2022/7/20 22:29
 * author: MR.孙
 */
@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Autowired
    private UserService userService;

    @GetMapping("/example")
    public Result<Map> get() {
        Map<String,Object> map = new HashMap<>();
        map.put("x", CollUtil.newArrayList("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"));
        map.put("y",CollUtil.newArrayList(new int[]{120, 132, 101, 134, 90, 230, 210},
                new int[]{220, 182, 191, 234, 290, 330, 310},
                new int[]{150, 232, 201, 154, 190, 330, 410},
                new int[]{320, 332, 301, 334, 390, 330, 320},
                new int[]{820, 932, 901, 934, 1290, 1330, 1320}));
        return Result.success(map);
    }

    @GetMapping("/members")
    public Result<ArrayList<Integer>> members(){
        List<User> list = userService.list();
        Integer q1=0;//第一季度
        Integer q2=0;//第二季度
        Integer q3=0;//第三季度
        Integer q4=0;//第四季度

        for(User user:list){
            Date createTime = user.getCreateTime();
            Quarter quarter = DateUtil.quarterEnum(createTime);
            switch (quarter){
                case Q1: q1+=1;break;
                case Q2: q2+=1;break;
                case Q3: q3+=1;break;
                case Q4: q4+=1;break;
                default:break;
            }
        }
        ArrayList<Integer> data = CollUtil.newArrayList(q1, q2, q3, q4);
        return Result.success(data);
    }
}
